// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
/* eslint-disable */
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueParticles from 'vue-particles'
import echarts from 'echarts'
import APlayer from '@moefe/vue-aplayer'

Vue.use(APlayer, {
  defaultCover: 'https://github.com/u3u.png',
  productionTip: true,
});

Vue.use(VueParticles)
Vue.use(ElementUI)
Vue.prototype.$echarts = echarts

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  //我在这里模仿了一个获取用户信息的方法
let isLogin = localStorage.getItem("authorization");
  if (isLogin) {
      //如果用户信息存在则往下执行。
      next()
  } else {
      //如果用户token不存在则跳转到login页面
      if (to.path === '/login') {
          next()
      }
      else if(to.path === '/register'){
        next()
      }
      else {
          next('/login')
      }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
